package com.chen.shopping_cart_customer_api.controller;


import com.chen.shopping_common.pojo.CartGoods;
import com.chen.shopping_common.result.BaseResult;
import com.chen.shopping_common.service.CartService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/cart")
public class CartController {

    @DubboReference
    private CartService cartService;

    @GetMapping("/findCartList")
    public BaseResult<List<CartGoods>> findCartList(@RequestHeader Long userId){
        List<CartGoods> cartList = cartService.getCartList(userId);
        return BaseResult.ok(cartList);
    }

    @PostMapping("/addCart")
    public BaseResult addCart(@RequestHeader Long userId,@RequestBody CartGoods cartGoods){
        cartService.addCart(userId, cartGoods);
        return BaseResult.ok();
    }

    @GetMapping("/handleCart")
    public BaseResult handleCart(@RequestHeader Long userId,Long goodId,Integer num){
        cartService.updateCart(userId,goodId,num);
        return BaseResult.ok();
    }

    @DeleteMapping("/deleteCart")
    public BaseResult deleteCart(@RequestHeader Long userId,Long goodId){
        cartService.deleteCart(userId, goodId);
        return BaseResult.ok();
    }
}
